package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.classManager.pojo.TUser;
import com.zhentao.classManager.pojo.vo.StudentVo;
import com.zhentao.classManager.pojo.vo.TeacherVo;
import com.zhentao.domain.StudentCount;
import com.zhentao.result.Result;
import com.zhentao.service.TUserService;
import com.zhentao.mapper.TUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author song-xinhang
* @description 针对表【t_user】的数据库操作Service实现
* @createDate 2024-07-24 10:08:50
*/
@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser>
    implements TUserService{
    @Resource
    private TUserMapper tUserMapper;

    @Override
    public Result selectTeacherClass(Integer userId) {
        List<TeacherVo> list = tUserMapper.selectTeacherClass(userId);
        return Result.OK(list);
    }

    @Override
    public Result selectStudentByClass(Integer classId) {
        List<TUser> tUsers = tUserMapper.selectList(Wrappers.<TUser>lambdaQuery().eq(TUser::getClassId, classId));
        return Result.OK(tUsers);
    }

    @Override
    public Result selectStudentExam(Integer studentId) {
        List<StudentVo> list = tUserMapper.selectStudentExam(studentId);
        return Result.OK(list);
    }

    @Override
    public Result selectTeacherClassInfo(Integer teacherId) {
        //查询出老师的班级信息以及班级的学生人数
        List<StudentCount> list = tUserMapper.selectTeacherClassInfo(teacherId);
        int totalStudentCount = 0;
        for (StudentCount studentCount : list) {
            totalStudentCount += studentCount.getValue();
        }
        for (StudentCount studentCount : list) {
            studentCount.setTotalStudentCount(totalStudentCount);
        }
        return Result.OK(list);
    }

    @Override
    public Result selectTeacherExamInfo(Integer userId) {
        List<StudentCount> list = tUserMapper.selectTeacherExamInfo(userId);
        return Result.OK(list);
    }
}




